import React from 'react'

import TestPropPassChild from './TestPropPassChild'

// let toBePass = {
//   name: "John",
//   age: 15
// }
let timer = null
class TestPropPass extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      toBePass: {
        name: "John",
        age: 15
      }
    }
  }

  componentDidMount () {
    timer = setTimeout(() => {
      this.setState((prevState, props) => {
        return {
          toBePass: { ...prevState.toBePass, name: "Mike" }
        }
      })
    }, 3000)
  }

  componentWillUnmount () {
    clearInterval(timer)
  }

  render () {
    return (
      <section>
        <TestPropPassChild passData={ this.state.toBePass }></TestPropPassChild>
      </section>
    )
  }
}

// setTimeout(() => {
//   toBePass.name = "Mike"
// }, 3000)

export default TestPropPass